<script setup lang="ts">
import { ref,onMounted, onActivated } from 'vue';
import request from '@/api/request.ts'
import dialog from '@/util/DialogTool';
import PersonInfoItem from '@/components/PersonInfoItem.vue';
import SectionTitle from '@/components/SectionTitle.vue';
import { useRoute } from 'vue-router';
import ColorItem from '@/components/ColorItem.vue';
import type {  PersonInfo, PersonVisitInfo, PersonVisitQueryResult } from '@/types/common';
import PersonGateTab from './components/personGateTab.vue';
import AskLeaveTab from './components/askLeaveTab.vue';
import carTab from './components/carTab.vue'
import { useUserStore } from '@/stores';
import { PermissionValues } from '@/types';
var pageNo = 1;
const asynDate = ref();
const noData = ref(false);
const carInfo = ref<PersonInfo>();
const taskList = ref<PersonVisitInfo[]>()
const loading = ref(false)
const finished = ref(false)
const refreshLoading = ref(false)
const route = useRoute();
const active = ref('askLeave');
const staffId = ref('')
const userStore = useUserStore();

onMounted(()=>{
    init()    
});

onActivated(()=>{
    active.value='askLeave'    
    init()    
})
 
const init = ()=>{
    //刷新列表
    pageNo = 1;    
    taskList.value = [];    
    getList();        
} 

const getList = ()=>{

    dialog.showLoading();

    staffId.value = route.query.id+"";
    request.get<PersonVisitQueryResult>('/query/queryPersonGate',{pageNo,staffId:staffId.value})
    .then((result)=>{
        dialog.closeToast();
        loading.value = false;
        refreshLoading.value = false;

        if(result.data){
            asynDate.value = result.data.asynDate            
            carInfo.value = result.data.person;

            if(result.data.list.length > 0){                
                if(!taskList.value) taskList.value=[];

                noData.value = false;
                taskList.value = taskList.value.concat( result.data.list);
                  noData.value=false;
            }else{
                //没有获取到新的内容
                if(pageNo > 1){
                    dialog.showToast('没有更多内容了');
                    noData.value = false;
                    finished.value = true;
                }
                if(pageNo ==  1){
                    noData.value=true;
                }
                
            }            
        }
    }).catch(()=>{
        loading.value = false;
        refreshLoading.value = false;
        dialog.closeToast();
    });

    
} 

</script>

<template>
<div class="personAllInfoDetail">
    <div class="favoPagetitle">
        人员详细信息
    </div>

    <div class="carBakInfo">
        <SectionTitle text="基本信息" />
    </div>

    <div class="carInfoContent">
        <ColorItem color="#FFA000" class="searchItem" :colorBorder="false"  style="border-radius: 0;border:none">            
            <PersonInfoItem :value="carInfo" :link="false"/>
        </ColorItem>
    </div>

    
    <van-tabs ref="tabs" v-model:active="active"  :ellipsis="false" :swipeable="true"    offset-top="20px"  >    
    <van-tab title="干部请假" name="askLeave"  v-if="userStore.hasPermission(PermissionValues.LEAVE_QUERY)">
      <template #title>        
          <div class="cutomeTabTitle" :class="active =='askLeave'?'active':''">干部请假</div>        
      </template>
      <div class="tabConent">
        <AskLeaveTab  :staff-id="staffId" />
      </div>
    </van-tab>
    
    <van-tab title="备案车辆" name="tab_car" v-if="userStore.hasPermission(PermissionValues.CAR_QUERY)">
      <template #title>        
          <div class="cutomeTabTitle" :class="active =='tab_car'?'active':''">备案车辆</div>
      </template>      
      <div class="tabConent" >        
        <carTab :staffId="staffId"/>
      </div>
    </van-tab>

    <van-tab title="行人进出" name="personGate"  v-if="userStore.hasPermission(PermissionValues.PERSON_QUERY)" >
      <template #title>        
          <div class="cutomeTabTitle" :class="active =='personGate'?'active':''">行人进出</div>        
      </template>
      <div class="tabConent">
        <PersonGateTab :id="staffId"/>
      </div>
    </van-tab>
    
    
    
  </van-tabs>

   
</div>
</template>

<style lang="less">
    .personAllInfoDetail{
        display: block;
        min-height: 300px;
        padding-top: 65px;

        .asynDate{
            text-align: center;
            padding:10px;
            font-size: 14px;
        }

        .cutomeTabTitle{
            font-size: 16px;
        }
        
        .favoPagetitle{
            font-size: 20px;            
            padding:20px;    
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 1;
            background: #fff;            
            border-bottom: 1px solid #f2f2f2;
            display: flex;
            height: 60px;
            align-items: center;
        }

      

        .carBakInfo{
            background-color: #fff;
            padding:10px;
            padding-bottom: 0;
        }
        
        .content{
            
            padding:10px;
            padding-top: 0;
            min-height: 400px;
            .loadMore{
                width: 100%;
                font-size: 12px;
                color: #4385f5;
                text-align: center;
                margin: 0.5rem auto 1rem;
            }
        }

        .carInfoContent{
            background-color: #fff;
            margin-bottom:10px;
            padding-left: 10px;
        }

        .carparkitem{
            background-color: #fff;
            margin-bottom: 6px;
        }

    }


</style>

<style lang="css">
   
 @media screen and (min-width: 1024px) {
  
    .favo  .content{
        margin-top: 15px;
        padding-left: 0;
        padding-right: 0;
    }
}
</style>